package com.smz.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.smz.entity.Supplier;
import com.smz.service.SupplierService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
public class SupplierController {

    @Autowired
    SupplierService supplierService;

    @GetMapping("/suppliers/{current}/{size}")
    public ResponseEntity<IPage<Supplier>> findSupplierPage(@PathVariable("current")int current , @PathVariable("size")int size){
        IPage<Supplier> supplierIPage = supplierService.findSupplierPage(current, size);
        return ResponseEntity.ok(supplierIPage);
    }
    @PutMapping("/supplier")
    public ResponseEntity<String> modifySupplier(@RequestBody Supplier supplier){
        supplierService.updateById(supplier);
        return ResponseEntity.ok("ok");
    }
    @GetMapping("/suppliers/{current}/{size}/{address}/{name}")
    public ResponseEntity<IPage<Supplier>> findLikeSupp(@PathVariable("current")int current , @PathVariable("size")int size, @PathVariable("address")String address , @PathVariable("name")String name){
        IPage<Supplier> supplierLikePage = supplierService.findSupplierLikePage(current, size, address, name);
        return ResponseEntity.ok(supplierLikePage);
    }
}
